package com.springboot.middleware.middleware_redisson.server.controller;

import com.google.common.base.Strings;
import com.springboot.middleware.middleware_redisson.api.enums.StatusCode;
import com.springboot.middleware.middleware_redisson.api.response.BaseResponse;
import com.springboot.middleware.middleware_redisson.server.dto.UserRegDto;
import com.springboot.middleware.middleware_redisson.server.service.UserRegService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserRegController {
    private static final Logger log = LoggerFactory.getLogger(QueueController.class);
    private static final String prefix = "user/reg";

    @Autowired
    private UserRegService userRegService;

    @RequestMapping(value = prefix + "/submit", method = RequestMethod.GET)
    public BaseResponse reg(UserRegDto dto) {
        if (Strings.isNullOrEmpty(dto.getUserName()) || Strings.isNullOrEmpty(dto.getPassword())) {
            return new BaseResponse(StatusCode.Fail);
        }
        BaseResponse baseResponse = new BaseResponse(StatusCode.Success);
        try {
            userRegService.userRegRedisson(dto);
        } catch (Exception e) {
            baseResponse = new BaseResponse(StatusCode.Fail.getCode(), e.getMessage());
        }
        return baseResponse;
    }
}
